<?php namespace App\Http\Requests;

use App\Http\Requests\Request;

class ItemRequest extends Request
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
            'describe' => 'required',
            'type' => 'required|in:lost,find',
            'p_catalog_id' => 'required|exists:catalogs,id,level,1',
            'catalog_id' => 'required|exists:catalogs,id,level,2',
            'province_id' => 'required|exists:areas,id,level,1',
            'city_id' => 'required|exists:areas,id,level,2',
            'district_id' => 'required|exists:areas,id,level,3',
            'place' => 'required',
            'wanted_fee' => 'numeric',
            'lost_time' => 'date_format:Y-m-d H:i:s',
            'find_time' => 'date_format:Y-m-d H:i:s',
        ];
    }


    public function messages()
    {
        return [
            'name.required' => '请填写名称',
            'describe.required' => '请填写描述',
            'type.required' => '请选择类型',
            'type.in' => '类型不符',
            'p_catalog_id.required' => '请选择一级分类',
            'p_catalog_id.exists' => '错误的分类',
            'catalog_id.required' => '请选择二级分类',
            'catalog_id.exists' => '错误的分类',
            'province_id.required' => '请选择省',
            'province_id.exists' => '错误的省',
            'city_id.required' => '请选择市',
            'city_id.exists' => '错误的市',
            'district_id.required' => '请选择区',
            'district_id.exists' => '错误的区',
            'place.required' => '请填写详细地址',
            'wanted_fee.numeric' => '请填写正确的金额',
            'lost_time.date_format' => '时间格式错误',
            'find_time.date_format' => '时间格式错误',
        ];
    }
}
